home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / xiafs / xiafspgm.8 / xiafspgm / xiafspgm-0.8.1 / secondary.s < prev    next >
Text File  |  1993-03-21  |  6KB  |  327 lines

  1. !-----------------------------------------------------------------------!
  2. ! secondary.s                                !
  3. !                                    !
  4. !   Copyright (C) Q. Frank Xia, 1993.  All rights reserved.        !
  5. !                                    !
  6. ! This software may be redistributed as per Linux copyright        !
  7. !                                    !
  8. !-----------------------------------------------------------------------!
  9.  
  10.  
  11. SETUPSECTS     = 4        ! nr of setup sectors
  12. BOOTSEG        = 0x07C0    ! original address of boot sector
  13. INITSEG       = 0x9000    ! we move boot here - out of the way
  14. SETUPSEG      = 0x9020    ! setup starts here
  15. SYSSEG        = 0x1000    ! system loaded at 0x10000 (65536).
  16. IMAGESEG      = 0        ! setup loaded at 0:0xf8000 first
  17. IMAGEOFF      = 0xf800    ! then moved to SETUPSEG:0x0000
  18.  
  19.     .text
  20.     .globl    _main
  21. _main:
  22.  
  23.  
  24. ! move this 512 byte to INITSEG:0x0000
  25.  
  26.     mov    ax, #BOOTSEG
  27.     mov    ds, ax
  28.     mov    ax, #INITSEG
  29.     mov    es, ax
  30.     mov    cx, #256
  31.     sub    si, si
  32.     sub    di, di
  33.     cld
  34.     rep
  35.     movsw
  36.     jmpi    start, INITSEG
  37.  
  38.  
  39. ! set up the segment registers and the stack
  40.  
  41. start:    
  42.     mov    ax, cs        ! setup seg registers    
  43.     mov    ds, ax        ! put stack at INITSEG:0x4000-12.
  44.     mov    es, ax
  45.     mov    ss, ax        
  46.     mov    ax, #0x4000-12    
  47.     mov    sp, ax
  48.  
  49.  
  50. ! get disk drive parameters
  51.  
  52.     movb    boot_disk, dl    ! save root disk code
  53.  
  54.     testb    dl, #0x80    ! hd or floppy ?
  55.     jz    floppy    
  56.  
  57.  
  58. ! get hard disk drive parameters
  59.  
  60.     mov    di, sp        ! hard disk boot
  61.     movb    ah, #0x08    ! find out the parameters of the hard disk
  62.     int    0x13
  63. die1:    jc    die1
  64.     andb    cl, #0x3f
  65.     movb    nr_sects, cl    
  66.     incb    dh
  67.     movb    nr_heads, dh
  68.     jmp    load_all
  69.  
  70.  
  71. ! get diskette drive parameters
  72.  
  73. floppy:
  74.     xor    ax, ax
  75.     mov    fs, ax
  76.     mov    bx, #0x78        ! fs:bx is parameter table address
  77.     seg fs
  78.     lgs    si, (bx)        ! gs:si is source
  79.     mov    di, dx            ! es:di is destination
  80.     mov    cx, #6            ! copy 12 bytes
  81.     cld
  82.     rep
  83.     seg gs
  84.     movsw
  85.  
  86.     mov    di, dx
  87.     movb    4(di), *18        ! patch sector count
  88.     seg fs
  89.     mov    (bx), di
  90.     seg fs
  91.     mov    2(bx), es
  92.     mov    ax, cs
  93.     mov    fs, ax
  94.     mov    gs, ax
  95.     xor    ah, ah            ! reset FDC 
  96.     xor    dl, dl
  97.     int     0x13    
  98.  
  99.  
  100. ! get parameters
  101.  
  102.     xor    dx, dx            ! drive 0, head 0
  103.     mov    cx, #0x0012        ! sector 18, track 0
  104.     mov    bx, #0x0200          ! address after setup (es = cs)
  105.     mov    ax, #0x0201        ! service 2, 1 sector
  106.     int    0x13
  107.     jnc    params_got
  108.     movb    cl, #0x0f        ! sector 15
  109.     mov    ax, #0x0201        ! service 2, 1 sector
  110.     int    0x13
  111.     jnc    params_got
  112. die2:    jmp    die2
  113.  
  114. params_got:
  115.     movb    nr_sects, cl
  116.     movb    nr_heads, #2
  117.  
  118.  
  119. ! load the kernel image
  120.  
  121. load_all:
  122.  
  123.     movb    al, nr_sects        ! calculate start cylinder,
  124.     mulb    nr_heads        ! head, secot_read
  125.     mov    cx, ax
  126.     mov    ax, Istart_lo
  127.     mov    dx, Istart_hi
  128.     div    cx
  129.     mov    cylinder, ax
  130.     mov    ax, dx
  131.     divb    nr_sects
  132.     movb    head, al
  133.     movb    sect_read, ah
  134.  
  135.     mov    bp, #msg_load        ! Print "loading"
  136.     call    print_string
  137.  
  138.     mov    ax, #IMAGESEG        ! load Image to 0:IMAGEOFF
  139.     mov    es, ax
  140.     mov    bx, #IMAGEOFF
  141.     call    do_load
  142.     call    move_setup
  143.     call    kill_motor
  144.     mov    bp, #msg_crlf
  145.     call    print_string
  146.  
  147.     mov    ax, root_dev        ! get root_dev device number
  148.     or    ax, ax            ! major and minor.
  149.     jne    root_defined
  150.     mov    bx, nr_sects
  151.     mov    ax, #0x0208        ! /dev/ps0 - 1.2Mb (2,8)
  152.     cmp    bx, #15
  153.     je    root_defined
  154.     mov    ax, #0x021c        ! /dev/PS0 - 1.44Mb (2,28)
  155.     cmp    bx, #18
  156.     je    root_defined
  157.     mov    ax, #0x0200        ! /dev/fd0 - autodetect
  158.  
  159. root_defined:
  160.     mov    root_dev, ax
  161.  
  162.     jmpi    0, SETUPSEG        ! load done, jump to setup seg
  163.  
  164. do_load:
  165.     mov     ax, es
  166.     test     ax, #0x0fff
  167. die3:    jne     die3            ! es must be at 64kB boundary
  168.  
  169. repeat_load:
  170.     mov     ax, es
  171.     cmp     ax, end_seg        ! have we loaded all yet?
  172.     jb     do_load_1
  173.     ret
  174. do_load_1:
  175.     movb     al, nr_sects
  176.     subb     al, sect_read
  177.     mov     cx, ax
  178.     shl     cx, #9
  179.     add     cx, bx
  180.     jnc     do_load_2
  181.     je     do_load_2
  182.     xor     ax, ax
  183.     sub     ax, bx
  184.     shr     ax, #9
  185. do_load_2:
  186.     call     read_track
  187.     movb     cl, al
  188.     addb     al, sect_read
  189.     cmpb     al, nr_sects
  190.     jne     do_load_3
  191.     mov     ax, #0
  192.     incb     head
  193.     movb    dl, head
  194.     cmpb    dl, nr_heads
  195.     jne    do_load_3
  196.     movb    head, #0
  197.     incb    cylinder
  198. do_load_3:
  199.     movb     sect_read, al
  200.     shl     cx, #9
  201.     add     bx, cx
  202.     jnc     repeat_load
  203.     mov     ax, es
  204.     add     ah, #0x10
  205.     mov     es, ax
  206.     xor     bx, bx
  207.     jmp     repeat_load
  208.  
  209. read_track:
  210.     pusha
  211.     pusha    
  212.     mov    ax, #0xe2e         ! print `.'
  213.     mov    bx, #7
  214.      int    0x10
  215.     popa        
  216.  
  217.     mov    dx, cylinder        ! al = # of sectors already loaded
  218.     movb    cl, sect_read
  219.     incb    cl            ! cl = sector, 1 related
  220.     movb    ch, dl            ! ch = sylinder
  221.     shlb    dh, #6            ! bit 6-7 of cl contains up 2 bits
  222.     orb    cl, dh            ! of cylinder
  223.     movb    dh, head        ! dh = head
  224.     movb    dl, boot_disk        ! dl = disk code
  225.     movb    ah, #2
  226.     
  227.     int    0x13
  228.     jc    read_err
  229.     popa
  230.     ret
  231.  
  232. read_err:    
  233.     mov    bp, #msg_err
  234.     call    print_string            ! ah = error, al = read
  235.         
  236.     xor     ah, ah
  237.     xor     dl, dl
  238.     int     0x13
  239.     
  240.     popa    
  241.     jmp     read_track
  242.  
  243. move_setup:
  244.     pusha
  245.     mov     ax, #IMAGESEG
  246.     mov    ds, ax
  247.     mov    si, #IMAGEOFF
  248.     mov    ax, #SETUPSEG
  249.     mov    es, ax
  250.     xor    di, di
  251.     mov    cx, #0x800
  252.     cld
  253.     rep
  254.     movsw
  255.     mov    ax, cx
  256.     mov    ds, ax
  257.     mov    es, ax
  258.     popa
  259.     ret
  260.  
  261.  
  262. ! print a string
  263. ! bp = address of the string to print
  264.  
  265. print_string:
  266.     pusha
  267.     push    bp
  268.     mov    ah, #0x03        ! read cursor pos
  269.     xor    bh, bh
  270.     int    0x10
  271.     pop    bp
  272.     mov    cx, #9
  273.     mov    bx, #0x0007        ! page 0, attribute 7 (normal)
  274.     mov    ax, #0x1301        ! write string, move cursor
  275.     int    0x10
  276.     popa
  277.     ret
  278.  
  279. ! kill the floppy motor
  280.  
  281. kill_motor:
  282.     push dx
  283.     mov dx, #0x3f2
  284.     xor al, al
  285.     outb
  286.     pop dx
  287.     ret
  288.  
  289. msg_load:
  290.     .byte 13, 10
  291.     .ascii "loading"
  292. msg_err:
  293.     .byte 13, 10
  294.     .ascii "retry"
  295. msg_crlf:
  296.     .byte 13, 10, 0
  297.  
  298. nr_sects:
  299.     .byte 9
  300. nr_heads:
  301.     .byte 2
  302.  
  303. sect_read:    
  304.     .byte 0            ! sectors read of current track
  305.  
  306. .org 496
  307. head:    
  308. Istart_lo:            ! Istart_lo, Istart_hi and end_seg
  309.     .word 1            ! are filled by mkboot.
  310. cylinder:    
  311. Istart_hi:
  312.     .word 0
  313. end_seg:
  314.     .word 0x4000
  315.  
  316. swap_dev:            ! root_dev may changed by mkboot.
  317.     .word 0            ! other feilds are copied from
  318. ram_size:            ! kernel image.
  319.     .word 0
  320. vid_mode:
  321.     .word 1
  322. root_dev:
  323.     .word 0            
  324. boot_disk:
  325. boot_flag:
  326.     .word 0xAA55
  327.